package com.rogue.system.controller;

import com.github.pagehelper.PageInfo;
import com.rogue.common.core.utils.ResultDTO;
import com.rogue.system.domain.dto.RoleDTO;
import com.rogue.system.domain.entity.SysRole;
import com.rogue.system.domain.vo.MenuVo;
import com.rogue.system.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author YeahLiang
 * @Create 2022/03/18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class RoleController {

    private final SysRoleService roleService;

    @PostMapping("/easyCreateRole")
    public ResultDTO<Boolean> easyCreateRole(@RequestBody RoleDTO roleDTO) {
        return ResultDTO.success(roleService.save(roleDTO));
    }

    @RequestMapping("/easyDeleteRole/{id}")
    public ResultDTO<Boolean> easyDeleteRole(@PathVariable Long id) {
        return ResultDTO.success(roleService.removeById(id));
    }

    @PostMapping("/easyUpdateRole")
    public ResultDTO<Boolean> easyUpdateRole(@RequestBody RoleDTO roleDTO) {
        return ResultDTO.success(roleService.updateById(roleDTO));
    }

    @RequestMapping("/easyGetOneRole/{id}")
    public ResultDTO<SysRole> easyGetOneRole(@PathVariable Long id) {
        return ResultDTO.success(roleService.getById(id));
    }

    @PostMapping("/setMenuForRole")
    public ResultDTO<Boolean> setMenuForRole(@RequestBody RoleDTO roleDTO){
        return ResultDTO.success(roleService.setMenuForRole(roleDTO));
    }

    @PostMapping("/removeRole")
    public ResultDTO<Boolean> removeRole(@RequestParam Long id){
        return ResultDTO.success(roleService.removeRole(id));
    }

    @PostMapping("/listRole")
    public ResultDTO<PageInfo<SysRole>> listRole(@RequestBody RoleDTO sysRole){
        return ResultDTO.success(roleService.listRole(sysRole));
    }

    @GetMapping("/getRoleByUserId/{id}")
    public ResultDTO<SysRole> getRoleByUserId(@PathVariable Long id){
        return ResultDTO.success(roleService.getByUserId(id));
    }

    @GetMapping("/getMenuByRoleId/{id}")
    public ResultDTO<List<MenuVo>> getMenuByRoleId(@PathVariable Long id){
        return ResultDTO.success(roleService.getMenuByRoleId(id));
    }
}
